 <html lang="en">
<head>
    <meta charset="UTF-8">
    <title>评价信息</title>
    <link href="css/swiper-5.4.5/swiper.min.css" rel="stylesheet">
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/my.css" rel="stylesheet">
    <link href="./css/font-awesome.css" rel="stylesheet">
    <link href="./css/element/index.css" rel="stylesheet">
    <style>
        .nx-nav-container ul{
            width: 100%;
            height: 100%;
            margin: 0 auto;
            display: flex;
            justify-content: center;
        }
        .nx-nav-container ul li{
            display: inline-block;
            width: 120px;
            text-align: center;
            line-height: 45px;
        }
        .nx-nav-container a{
            color: #FFFFFF;
        }
        .nx-nav-container a:hover {
            color: aquamarine;
            text-decoration: none;
        }
        td{
            vertical-align: middle !important;
        }
    </style>
</head>
<body>
<div id="wrapper">
    <div class="nx-header">
        <div style="display: flex;width: 100%;height: 30px;line-height: 30px;background-color: #eee;">
            <div style="flex: 5;padding: 0 10px; color: orangered;">
                欢迎访问 电影订票购票系统
            </div>
            <div v-if="user.name" style="flex: 1">
                欢迎您： {{user.name}}
                <a style="margin-left: 30px;color: blue;" href="javascript:void(0);" @click="logout">退出</a>
            </div>
        </div>
    </div>

    <div style="height: 80px; line-height: 80px;">
        <div style="margin-left: 20px;position: relative;">
            <img src="img/logo1.png" style="width: 40px;position: absolute;top: 20px;">
            <b style="margin-left: 45px;font-size:25px;text-shadow: 5px 5px 3px #888888">电影订票购票系统</b>
        </div>
    </div>

    <div class="nx-nav-container" style="height: 45px;background-color: black;">
        <ul>
            <li><a href="index.html">首页</a></li>
            <li><a href="advertiserInfo.html">公告信息</a></li>
            <li><a href="messageInfo.html">在线交流信息</a></li>
            <li><a href="linkInfo.html">友情链接</a></li>
            <li><a href="cartInfo.html">收藏栏信息</a></li>
            <li><a href="orderInfo.html">订单信息</a></li>
            <li class="active"><a href="commonInfo.html">评价信息</a></li>
            <li><a href="javascript:void(0)" @click="personalPage">个人信息</a></li>
            <li v-if="isShow"><a href="/end/page/index.html" target="_blank">进入后台系统</a></li>
            <li v-if="!isLogin"><a href="/end/page/login.html" target="_blank">登录</a></li>
            <li v-if="!isLogin"><a href="/end/page/register.html" target="_blank">注册</a></li>
        </ul>
    </div>

    <div class="container" style="margin-top: 20px;">
        <div class="col-md-12">
            <table class="table table-striped table-bordered table-hover">
                <thead>
                    <tr style="background-color: #cccccc">
                        <th>商品</th>
                        <th>状态</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    <tr v-for="(item, index) in goodsList" :key="item.id">
                        <td style="width: 230px;">
                            <div style="margin-bottom: 5px;display: flex;align-items:center">
                                <a href="'/front/goodsInfo.html?goodsId=' + item.id" target="_blank">
                                    <img style="width: 50%;height: 50%;" :src=item.imgSrc>
                                    <span style="font-size: 12px;margin-left: 10px;">
                                        {{item.name}}
                                    </span>
                                </a>
                            </div>
                        </td>
                        <td>
                            {{item.commentStatus}}
                        </td>
                        <td>
                            <button class="btn btn-primary btn-xs" @click="openModal(item)">
                                评价
                            </button>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
    <!-- 评价弹窗 -->
    <div class="modal fade" id="commentModal" tabindex="-1">
        <div class="modal-dialog">
            <div class="modal-content" style="width: 800px;">
                <div class="modal-header">
                    <span class="modal-title">请填写评价</span>
                    <button type="button" class="close" data-dismiss="modal" @click="entity={}">&times;</button>
                </div>
                <div class="modal-body">
                    <div class="form-horizontal">
                        <input type="hidden" name="id" v-model="commentInfo.goodsId">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">评价内容</label>
                            <div class="col-sm-7">
                                <textarea type="text" class="form-control" v-model="commentInfo.content" placeholder="请输入评价内容"></textarea>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" @click="submitComment()">保存</button>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="js/jquery-1.10.2.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/swiper-5.4.5/swiper.min.js"></script>
<script src="js/vue2.6.11/vue.min.js"></script>
<script src="js/vue2.6.11/axios.js"></script>
<script src="js/my.js"></script>
<script>
    new Vue({
        el: "#wrapper",
        data: {
            user: {}, // 当前登录用户
            isShow: false, // 是否显示进入后台
            isLogin: false, //是否已经登陆
            goodsList: [], // 电影列表
            commentInfo: {
                goodsId: 0,
                conten: ''
            }, // 弹出的模态框对象
        },
        created: function () {
            this.loadGoodsInfo(1);
        },
        methods: {
            // 加载以观看完成的电影列表
            loadGoodsInfo(pageNum){
                // 查询权限
                axios.get('/auth').then(res =>{
                    if(res.data.code == '0'){
                        this.user = res.data.data;
                        // 若是管理员
                        if(this.user.level === 1){
                            // 显示可以进入后台
                            this.isShow = true;
                        }
                        this.isLogin = true;
                        // 获取已观看完成的电影列表
                        axios.get("/goodsInfo/comment/" + this.user.id + "/" + this.user.level).then(res => {
                            if(res.data.code === '0'){
                                let goodsList = res.data.data;
                                goodsList.forEach(g =>{
                                    //获取展示图
                                    g.imgSrc = '/front/img/goods/dafault.png';
                                    if(g.fields){
                                        let fields1 = JSON.parse(g.fields);
                                        if(fields1.length){
                                            g.imgSrc = '/files/download/' + fields1[0];
                                        }
                                    }
                                });
                                this.goodsList = goodsList;
                            }else{
                                alert(res.data.msg);
                            }
                        });
                    }else{
                        alert('请先登录');
                        location.href = '/end/page/login.html';
                    }
                });
            },
            // 打开模态框
            openModal(data){
                this.commentInfo.goodsId = data.id;
                this.commentInfo.content = '';
                $('#commentModal').modal('show');
            },
            // 提交评价
            submitComment(){
                let data = {userId: this.user.id, level: this.user.level, content:this.commentInfo.content,goodsId: this.commentInfo.goodsId};
                axios.post('/commentInfo', data).then(res => {
                    if(res.data.code === '0'){
                        $('#commentModal').modal('hide');
                        alert('评价成功');
                        this.loadGoodsInfo(1);
                    }else{
                        alert(res.data.msg);
                    }
                })
            },
            logout(){
                axios.get('/logout').then(res =>{
                    if(res.data.code === '0'){
                        location.href = '/front/index.html';
                    }else{
                        alert(res.data.msg);
                    }
                });
            },
        }
    });
</script>
</body>
</html>